
<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="姓名" prop="userName">
				<el-input v-model="form.userName"></el-input>
			</el-form-item>
			<el-form-item label="性别" prop="sex">
				<el-select v-model="form.sex" :style="{width: '100%'}">
					<el-option v-for="item in sexData" :key="index" :value="item.value" :label="item.label"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="出生日期" prop="birthday">
				<el-date-picker v-model="form.birthday" format="yyyy-MM-dd HH:mm:ss" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}"
				 placeholder="请输入时间" clearable>
				</el-date-picker>
			</el-form-item>
			<el-form-item label="健康卡号/身份证号" prop="idCard">
				<el-input v-model="form.idCard"></el-input>
			</el-form-item>
			<el-form-item label="联系方式" prop="phoneNum">
				<el-input v-model="form.phoneNum"></el-input>
			</el-form-item>
			<el-form-item label="现住址" prop="adress">
				<el-input v-model="form.adress"></el-input>
			</el-form-item>
			<el-form-item label="居住环境" prop="livingCondition">
				<el-input v-model="form.livingCondition"></el-input>
			</el-form-item>
			<el-form-item label="工作" prop="work">
				<el-input v-model="form.work"></el-input>
			</el-form-item>
			<el-form-item label="爱好" prop="hobby">
				<el-input v-model="form.hobby"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	export default {
		name: 'KfRegisterEdit',
		components: {

		},
		props: ['editrecId'],
		data() {
			return {
				form: {
					userName: '',
					sex: '',
					birthday: null,
					idCard: '',
					phoneNum: '',
					adress: '',
					livingCondition: '',
					work: '',
					hobby: ''

				},
				sexData: [{
					"label": "男",
					"value": "男"
				}, {
					"label": "女",
					"value": "女"
				}],
				url: '/kfRegister/add'
			}
		},
		created() {
			console.log("this.editrecId:" + this.editrecId)
			if (this.editrecId) {
				this.url = '/kfRegister/update'
				this.axios.get('/kfRegister/toedit', resp => {
					this.form.recId = resp.obj.recId
					this.form.userName = resp.obj.userName
					this.form.sex = resp.obj.sex
					this.form.birthday = resp.obj.birthday
					this.form.idCard = resp.obj.idCard
					this.form.phoneNum = resp.obj.phoneNum
					this.form.adress = resp.obj.adress
					this.form.livingCondition = resp.obj.livingCondition
					this.form.work = resp.obj.work
					this.form.hobby = resp.obj.hobby
				}, {
					recId: this.editrecId
				})
			}
		},
		methods: {

			save() {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false)
							this.$emit('getData')
						}, this.form)
					}
				})
			}
		}
	}
</script>
<style>
